package com.hp.attendance.serlvet.role;

import com.hp.attendance.entity.RoleMenu;
import com.hp.attendance.service.RoleService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;

@WebServlet("/addDistriMenu")
public class MenuAddDisTriServlet extends HttpServlet {
    private RoleService roleService = new RoleService();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //分配菜单
        int roleId = Integer.parseInt(req.getParameter("roleId"));
        String[] menuIds = req.getParameterValues("menucheck");
        ArrayList<RoleMenu> list = new ArrayList<RoleMenu>();
        for (int i = 0; i < menuIds.length; i++) {
            int menuId = Integer.parseInt(menuIds[i]);
            list.add(new RoleMenu(roleId,menuId));
        }
        roleService.dittriMenu(list,roleId);
        //返回到哪里去
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
